using System;
using System.Collections.Generic;
using System.Text;
using FireStarter.CodeGeneration;
using FireStarter.CodeGeneration.Generator;
using FireStarter.CodeGeneration.Parser;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration.Parser
{
    [TestFixture]
    public class TestValueExpressionParser
    {
        private static readonly List<IActionParser> _defaultActionParsers = new List<IActionParser>() { new ValueExpressionParser(), new ForEachExpressionParser() };

        [Test]
        public void Test_Parse()
        {
            //---------------Set up test pack-------------------
            string propertyName = TestUtilsCodeGen.GetRandomString();
            string text = "=" + propertyName;
            IParser parser = new ValueExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            TemplateExpression templateExpression = parser.Parse(ref text, _defaultActionParsers);
            //---------------Test Result -----------------------
            ParserTestUtils.AssertExpressionIsValue(propertyName, templateExpression);
            Assert.AreEqual("", text);
        }

        [Test]
        public void Test_Parse_WithWhitespace()
        {
            //---------------Set up test pack-------------------
            string propertyName = TestUtilsCodeGen.GetRandomString();
            string text = "=" + propertyName + TestUtilsCodeGen.GetRandomWhiteSpace();
            IParser parser = new ValueExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            TemplateExpression templateExpression = parser.Parse(ref text, _defaultActionParsers);
            //---------------Test Result -----------------------
            ParserTestUtils.AssertExpressionIsValue(propertyName, templateExpression);
            Assert.AreEqual("", text);
        }

        [Test]
        public void Test_IsExpressionMatch()
        {
            //---------------Set up test pack-------------------
            string propertyName = TestUtilsCodeGen.GetRandomString();
            string text = "=" + propertyName;
            ValueExpressionParser parser = new ValueExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsTrue(isExpressionMatch);
        }

        [Test]
        public void Test_IsExpressionMatch_Fails_IfNoEquals()
        {
            //---------------Set up test pack-------------------
            string propertyName = TestUtilsCodeGen.GetRandomString();
            string text = propertyName;
            ValueExpressionParser parser = new ValueExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsFalse(isExpressionMatch);
        }
        
        [Test]
        public void Test_IsExpressionMatch_Fails_IfNull()
        {
            //---------------Set up test pack-------------------
            string text = null;
            ValueExpressionParser parser = new ValueExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsFalse(isExpressionMatch);
        }
 
        [Test]
        public void Test_IsExpressionMatch_Fails_IfEmpty()
        {
            //---------------Set up test pack-------------------
            string text = "";
            ValueExpressionParser parser = new ValueExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsFalse(isExpressionMatch);
        } 

        //TODO: What if it is "==". Validation?

    }
}
